#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
爬虫配置文件 - 存储爬虫相关的配置信息
"""

# 网站基础配置
WEBSITE_CONFIG = {
    'base_url': 'https://wmqxz.net',
    'domain': 'wmqxz.net',
    'protocol': 'https'
}

# 解密配置
DECRYPT_CONFIG = {
    # 从JavaScript代码中提取的默认密钥
    'default_key': 'GcgzsKdDZTumABNz7uujrCfPIk9TQ355',
    
    # 其他可能的密钥（从代码中发现的）
    'alternative_keys': [
        '66JY6UGvib6b5Dpj',
        'bd5d212d30324ff6',
    ],
    
    # AES配置
    'algorithm': 'AES',
    'mode': 'ECB',
    'padding': 'PKCS7',
    'encoding': 'base64'
}

# API端点配置
API_ENDPOINTS = {
    # 用户相关
    'login': '/cluser/c/user/mac/login',
    'user_info': '/cluser/c/user/stationGroup/other',
    
    # 媒体相关
    'list_media': '/member/media/stationGroup/listMediaBySearchType',
    'media_detail': '/member/media/detail',
    'media_list': '/member/media/list',
    
    # 系统相关
    'banner_click': '/system/bannersetting/clickBanner',
    'fetch_data': '/api/fetch-data',
}

# 请求头配置
DEFAULT_HEADERS = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
    'Accept': 'application/json, text/plain, */*',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
    'Accept-Encoding': 'gzip, deflate, br',
    'Connection': 'keep-alive',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'Cache-Control': 'no-cache',
    'Pragma': 'no-cache'
}

# API请求头配置
API_HEADERS = {
    'Content-Type': 'application/json;charset=utf-8',
    'language': 'en_US',
    'os': '2',
    'ver': '1.0'
}

# 请求配置
REQUEST_CONFIG = {
    'timeout': 30,
    'max_retries': 3,
    'retry_delay': 1,
    'verify_ssl': True,
    'allow_redirects': True
}

# 搜索配置
SEARCH_CONFIG = {
    'default_search_type': 1,
    'default_page_size': 20,
    'max_page_size': 100,
    'search_types': {
        1: '综合搜索',
        2: '视频搜索',
        3: '音频搜索',
        4: '图片搜索'
    }
}

# 设备配置
DEVICE_CONFIG = {
    'device_id_length': 24,
    'merchant_account': 'default_merchant',  # 需要从实际网站获取
    'agent_code': 'TDV6MC4J',  # 从JavaScript代码中提取
    'platform': {
        'os': '2',  # 2表示Web平台
        'version': '1.0'
    }
}

def get_full_url(endpoint):
    """获取完整的URL"""
    base_url = WEBSITE_CONFIG['base_url']
    if endpoint in API_ENDPOINTS:
        endpoint = API_ENDPOINTS[endpoint]
    return f"{base_url}{endpoint}"

def get_headers(include_api_headers=True):
    """获取请求头"""
    headers = DEFAULT_HEADERS.copy()
    if include_api_headers:
        headers.update(API_HEADERS)
    return headers

def get_search_types():
    """获取搜索类型列表"""
    return SEARCH_CONFIG['search_types']

def validate_config():
    """验证配置的有效性"""
    errors = []
    
    # 检查必要的配置
    if not DECRYPT_CONFIG['default_key']:
        errors.append("缺少默认解密密钥")
    
    if not WEBSITE_CONFIG['base_url']:
        errors.append("缺少网站基础URL")
    
    # 检查密钥长度
    key = DECRYPT_CONFIG['default_key']
    if len(key.encode('utf-8')) not in [16, 24, 32]:
        errors.append(f"密钥长度不符合AES要求: {len(key.encode('utf-8'))}")
    
    return errors

if __name__ == "__main__":
    # 验证配置
    errors = validate_config()
    if errors:
        print("配置验证失败:")
        for error in errors:
            print(f"  - {error}")
    else:
        print("配置验证通过")
    
    # 显示主要配置信息
    print(f"\n网站: {WEBSITE_CONFIG['base_url']}")
    print(f"默认密钥: {DECRYPT_CONFIG['default_key']}")
    print(f"搜索端点: {get_full_url('search_media')}")
    print(f"支持的搜索类型: {list(get_search_types().values())}")
